package cn.lyvust.demo.shili07;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;

/**
 * Description:
 * date: 2021-5-10 21:45
 *
 * @author Guo_guo
 * @since JDK 1.8
 */
public class CollectionsDemo {
    public static void main(String[] args) {
        Student student1=new Student();
        student1.setNumber(5);
        Student student2=new Student();
        student2.setNumber(2);
        Student student3=new Student();
        student3.setNumber(1);
        Student student4=new Student();
        student4.setNumber(4);
        ArrayList<Student> list=new ArrayList<Student>();
        list.add(student1);
        list.add(student2);
        list.add(student3);
        list.add(student4);
        System.out.println("-------排序前-------");
        Iterator<Student> iterator=list.iterator();
        while(iterator.hasNext()){
            Student stu=iterator.next();
            System.out.println(stu.getNumber());
        }
        //使用Collections的sort方法对list进行排序
        System.out.println("-------排序后-------");
        Collections.sort(list);
        iterator=list.iterator();
        while(iterator.hasNext()){
            Student stu=iterator.next();
            System.out.println(stu.getNumber());
        }
    }
}
